#!/bin/bash
# set -e

if [ $# -ne 6 ];then
	echo "$0 param num wrong!!!"
	exit 1
fi

VERSION_INI=$1
BUILD_PATH=$2
BIN_PATH=$3
TAGET_NAME=$4
CRC_INSERT=$5
TOOL_PATH=$6


if [ ! -f $VERSION_INI ]; then
	echo "$VERSION_INI not exist!!!"
	exit 1
fi

if [ ! -f $BUILD_PATH/$TAGET_NAME.hex ]; then
	echo "$BUILD_PATH/$TAGET_NAME.hex not exist!!!"
	exit 1
fi

if [ ! -d $BIN_PATH ];then
	mkdir $BIN_PATH
else
	rm -rf $BIN_PATH/*
fi

source crc_tools.rc

# echo VERSION_INI=$VERSION_INI
# echo BUILD_PATH=$BUILD_PATH
# echo BIN_PATH=$BIN_PATH
if [ "s$CRC_INSERT" == "s1" ];then
	ecu_crc_generater $TOOL_PATH $BUILD_PATH $TAGET_NAME $VERSION_INI $BIN_PATH 
elif [ "s$CRC_INSERT" == "s2" ];then
	vcu_crc_generater $TOOL_PATH $BUILD_PATH $TAGET_NAME $VERSION_INI $BIN_PATH
else
	no_crc_generater $TOOL_PATH $BUILD_PATH $TAGET_NAME $VERSION_INI $BIN_PATH
fi
